package chapter4.No4_1_使用reentrantLock类.demo15;

/**
 * *：
 *    方法boolean tryLock()
 *      仅在调用时锁定未被另一个线程保持的情况下，才获取该锁定
 *
 *    boolean tryLock(long timeout, TimeUnit unit)
 *      如果锁定在给定等待时间内没有被另一个线程保持，并且当前线程
 *      未被中断，则获取该锁定
 * Created by Administrator on 2016/11/22.
 */
public class Main3 {
    public static void main(String[] args) throws InterruptedException {
        final ServiceClass3 sc = new ServiceClass3();
        Runnable runnable = new Runnable() {
            public void run() {
                System.out.println(Thread.currentThread().getName()+" 开始启动"+System.currentTimeMillis());
                sc.methodA();
            }
        };
        Thread a = new Thread(runnable);
        a.setName("a");
        a.start();
        Thread b = new Thread(runnable);
        b.setName("b");
        b.start();
    }
}
